package yxk.operation;

import kd.bos.dataentity.OperateOption;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.entity.operate.result.OperationResult;
import kd.bos.entity.plugin.AbstractOperationServicePlugIn;
import kd.bos.entity.plugin.args.AfterOperationArgs;
import kd.bos.logging.Log;
import kd.bos.logging.LogFactory;
import kd.bos.orm.query.QCP;
import kd.bos.orm.query.QFilter;
import kd.bos.servicehelper.BusinessDataServiceHelper;
import kd.bos.servicehelper.operation.OperationServiceHelper;
import kd.bos.servicehelper.operation.SaveServiceHelper;
import kd.sdk.plugin.Plugin;

import java.util.ArrayList;
import java.util.List;

/**
 * 考勤档案-考勤周期修改
 */
public class PeriodsCheduledgOperationPlugln extends AbstractOperationServicePlugIn implements Plugin {
    private final Log log = LogFactory.getLog(PeriodsCheduledgOperationPlugln.class);
    @Override
    public void afterExecuteOperationTransaction(AfterOperationArgs e) {

        String operationKey = e.getOperationKey();
        if("don_update".equals(operationKey)) {
            DynamicObject[] entities = e.getDataEntities();
            DynamicObject attperiod = BusinessDataServiceHelper.loadSingle("wtp_attperiod", "id", new QFilter("number", QCP.equals, "2040").toArray());
            log.info("afterExecuteOperationTransaction.attperiod:{}",attperiod);
            DynamicObject[] rows = new DynamicObject[entities.length];
            int i=0;
            for (DynamicObject entity : entities) {
                DynamicObject single = BusinessDataServiceHelper.loadSingle(entity.getPkValue(), entity.getDynamicObjectType().getName());
                single.set("period",attperiod);
                rows[i]=single;
                ++i;
            }
            OperationResult operationResult = OperationServiceHelper.executeOperate("save", "wtp_periodschedule_dg",rows, OperateOption.create());
        }
    }
}